﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BLL;
using Public;

namespace QLNhanKhau
{
    public partial class frmThietLap : Form
    {
        public frmThietLap()
        {
            InitializeComponent();
        }
        private void frmThietLap_Load(object sender, EventArgs e)
        {

            cmbTinh.DataSource = TinhBLL.LoadTinh();
            cmbTinh.DisplayMember = "TenTinh";
            cmbTinh.ValueMember = "MaT";

            cmbTinh.SelectedIndex = -1;
            cmbTinh.Text = "   --- Chọn Tỉnh ---   ";

            cmbQuanHuyen.Text = "  --- Chọn Huyện ---  ";
            cmbPhuongXa.Text = "    --- Chọn Xã ---   ";
            //cmbTinh.Text.

            //cmbQuanHuyen.DataSource = QuanHuyenBLL.LoadQuanHuyen();
            //cmbQuanHuyen.DisplayMember = "TenQuanHuyen";
            //cmbQuanHuyen.ValueMember = "MaQH";

            //cmbQuanHuyen.SelectedIndex = -1;
            //load xã
            //cmbPhuongXa.BindingContext = new BindingContext();
            //QuanHuyenPublic px = QuanHuyenBLL.LoadQuanHuyenByMaQH((byte)cmbQuanHuyen.SelectedValue);
            //cmbPhuongXa.DataSource = PhuongXaBLL.LoadPhuongXaByMaQH(px.MaQH);
            //cmbPhuongXa.DisplayMember = "TenPhuongXa";
            //cmbPhuongXa.ValueMember = "MaPX";


        }
        private void cmbQuanHuyen_SelectionChangeCommitted(object sender, EventArgs e)
        {
            //QuanHuyenPublic px = QuanHuyenBLL.LoadQuanHuyenByMaQH((byte)cmbQuanHuyen.SelectedValue);
            cmbPhuongXa.DataSource = PhuongXaBLL.LoadPhuongXaByMaQH((int)cmbQuanHuyen.SelectedValue);
            cmbPhuongXa.DisplayMember = "TenPhuongXa";
            cmbPhuongXa.ValueMember = "MaPX";
            cmbPhuongXa.SelectedIndex = -1;
            cmbPhuongXa.SelectedText = "    --- Chọn Xã ---   ";

        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            ThietLapPublic tl = new ThietLapPublic();
            tl.MaPX = (int)cmbPhuongXa.SelectedValue;
            //tl.MaQH = (byte)cmbQuanHuyen.SelectedValue;
            //tl.MaT = (byte)cmbTinh.SelectedValue;
            ThietLapBLL.InsertThietLap(tl);
            MessageBox.Show("Lưu thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();
        }
        private void btnThoat_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Thoát không lưu", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            if (result == DialogResult.Yes)
            {
                this.MdiParent = null;
                this.Dispose();

            }
        }

        private void cmbTinh_SelectionChangeCommitted(object sender, EventArgs e)
        {
            cmbQuanHuyen.DataSource = QuanHuyenBLL.LoadQuanHuyenByMaT((int)cmbTinh.SelectedValue);
            cmbQuanHuyen.DisplayMember = "TenQuanHuyen";
            cmbQuanHuyen.ValueMember = "MaQH";
            cmbQuanHuyen.SelectedIndex = -1;
            cmbQuanHuyen.SelectedText = "  --- Chọn Huyện ---  ";

        }
    }
}
